//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Media;
using OpenLS.Core.Serialization;
using OpenLS.Drawing.Serialization;

namespace OpenLS.Drawing
{
    public class ThemeColor : ColorBase
    {
        private SchemeColorValue val;

        public ThemeColor()
        {
        }

        public ThemeColor(SchemeColorValue val)
        {
            this.val = val;
        }

        public ThemeColor(SchemeColorValue val, double tint) : this(val)
        {
            Transforms.Add(new TintTransform(tint*100));
        }

        public SchemeColorValue Value
        {
            get { return val; }
            //\\ set { val = value; }
        }


        protected override Color ResolveRawColor(ColorScheme colorScheme)
        {
            if (colorScheme == null)
            {
                colorScheme = BuiltInThemes.DefaultTheme.ColorScheme;
            }
            //\\return Colors.Pink;

            switch (Value)
            {
                case SchemeColorValue.Accent1:
                    return colorScheme.Accent1.ResolveColor(colorScheme);
                case SchemeColorValue.Accent2:
                    return colorScheme.Accent2.ResolveColor(colorScheme);
                case SchemeColorValue.Accent3:
                    return colorScheme.Accent3.ResolveColor(colorScheme);
                case SchemeColorValue.Accent4:
                    return colorScheme.Accent4.ResolveColor(colorScheme);
                case SchemeColorValue.Accent5:
                    return colorScheme.Accent5.ResolveColor(colorScheme);
                case SchemeColorValue.Accent6:
                    return colorScheme.Accent6.ResolveColor(colorScheme);
                case SchemeColorValue.Dark1:
                    return colorScheme.Dark1.ResolveColor(colorScheme);
                case SchemeColorValue.Dark2:
                    return colorScheme.Dark2.ResolveColor(colorScheme);
                case SchemeColorValue.Light1:
                    return colorScheme.Light1.ResolveColor(colorScheme);
                case SchemeColorValue.Light2:
                    return colorScheme.Light2.ResolveColor(colorScheme);
                case SchemeColorValue.Text1:
                    return colorScheme.Dark1.ResolveColor(colorScheme); //\\?
                case SchemeColorValue.Text2:
                    return colorScheme.Dark2.ResolveColor(colorScheme);
                case SchemeColorValue.Background1:
                    return colorScheme.Light1.ResolveColor(colorScheme);
                case SchemeColorValue.Background2:
                    return colorScheme.Light2.ResolveColor(colorScheme);
                default:
                    throw new NotSupportedException();
            }
        }


        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read(DrawingConstants.DrawingNamespace +  "schemeClr"))
            {
                val = c.GetEnum<SchemeColorValue>("val");
                ReadTransforms(c);
            }
        }


       //\\ public event EventHandler ColorChanged;

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write(DrawingConstants.DrawingNamespace + "schemeClr"))
            {
                c.SetEnum("val", Value);
                WriteTransforms(c);
            }
        }
    }
}